import {
  mapGetters
} from 'vuex'
export default {
  computed: {
    ...mapGetters('cart', ['total'])
  },
  onShow() {
    uni.setTabBarBadge({
      index: 2,
      text: this.total + ''
    })
  },
  watch: {
    total: {
      handler(newVal) {
        // console.log('newVal', newVal);
        // 页面路由数据获取  getCurrentPages
        const pagesArr = getCurrentPages()
        if (pagesArr.length > 0) {
          const currRoute = pagesArr[pagesArr.length - 1].route
          const tabbarArr = ['pages/home/home', 'pages/cart/cart', 'pages/cate/cate', 'pages/my/my']
          if (tabbarArr.includes(currRoute)) {
            uni.setTabBarBadge({
              index: 2,
              text: newVal + ''
            })
          }
        }
      },
      immediate: true
    }
  },

}